From a2f687a57b6ecd798f3b64a1af9c1e2c3c6b66c0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 19 Aug 2016 21:00:21 +0300 Subject: [PATCH] Don't require current package in resolve_ws --- src/cargo/core/workspace.rs | 18 +++++++++++------- src/cargo/ops/resolve.rs | 4 +++- tests/install.rs | 3 ++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index d4c32e572..bdf00a44e 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -6,7 +6,7 @@ use std::slice; use core::{Package, VirtualManifest, EitherManifest, SourceId}; use core::{PackageIdSpec, Dependency}; use ops; -use util::{Config, CargoResult, Filesystem}; +use util::{Config, CargoResult, Filesystem, human}; use util::paths; /// The core abstraction in Cargo for working with a workspace of crates. @@ -143,13 +143,17 @@ impl<'cfg> Workspace<'cfg> { /// actually a "virtual Cargo.toml", in which case an error is returned /// indicating that something else should be passed. pub fn current(&self) -> CargoResult<&Package> { + self.current_opt().ok_or_else(|| + human(format!("manifest path `{}` is a virtual manifest, but this \ + command requires running against an actual package in \ + this workspace", self.current_manifest.display())) + ) + } + + pub fn current_opt(&self) -> Option<&Package> { match *self.packages.get(&self.current_manifest) { - MaybePackage::Package(ref p) => Ok(p), - MaybePackage::Virtual(..) => { - bail!("manifest path `{}` is a virtual manifest, but this \ - command requires running against an actual package in \ - this workspace", self.current_manifest.display()) - } + MaybePackage::Package(ref p) => Some(p), + MaybePackage::Virtual(..) => None } } diff --git a/src/cargo/ops/resolve.rs b/src/cargo/ops/resolve.rs index 9ec3f55f4..eb5713294 100644 --- a/src/cargo/ops/resolve.rs +++ b/src/cargo/ops/resolve.rs @@ -17,7 +17,9 @@ pub fn resolve_ws(registry: &mut PackageRegistry, ws: &Workspace) let resolve = try!(resolve_with_previous(registry, ws, Method::Everything, prev.as_ref(), None)); - if try!(ws.current()).package_id().source_id().is_path() { + + // Avoid writing a lockfile if we are `cargo install`ing a non local package. + if ws.current_opt().map(|pkg| pkg.package_id().source_id().is_path()).unwrap_or(true) { try!(ops::write_pkg_lockfile(ws, &resolve)); } Ok(resolve) diff --git a/tests/install.rs b/tests/install.rs index af6efcfad..45eabb782 100644 --- a/tests/install.rs +++ b/tests/install.rs @@ -555,7 +555,8 @@ fn git_repo() { .file("src/main.rs", "fn main() {}"); p.build(); - assert_that(cargo_process("install").arg("--git").arg(p.url().to_string()), + // use `--locked` to test that we don't even try to write a lockfile + assert_that(cargo_process("install").arg("--locked").arg("--git").arg(p.url().to_string()), execs().with_status(0).with_stderr(&format!("\ [UPDATING] git repository `[..]` [COMPILING] foo v0.1.0 ([..]) -- 2.30.2